package com.workflow.listener;

import com.gec.service.abst.LeaveService;
import com.gec.utils.MyWebUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;

public class LeaveEndHandler implements ExecutionListener {
    private LeaveService leaveService;

    public LeaveEndHandler() {
        //{ps}在这里装配 leaveService.
        leaveService = MyWebUtils.getBean(LeaveService.class);
    }

    @Override
    public void notify(DelegateExecution execution) {
        //{1}先获取流程变量cancel
        boolean isCancel = Boolean.parseBoolean((String) execution.getVariable("cancel"));
        //{2}根据流程变量来设置'已取消' '已办结'
        String status = isCancel?"已取消":"已办结";
        //{3}获取流程实列ID
        String proInsID = execution.getProcessInstanceId();
        //{4}更新t_leave表中的状态
        //更新=>【'已取消' '已办结'】
        leaveService.updateStatusByInstance(proInsID,status);
        //{5}清空【办理人】与任务【ID】
        leaveService.clearTaskAndAssignee(proInsID);
    }
}
